#!/bin/sh

# author: tzm529

nginx_log_path="/home/tzm529/study/"
backup_log_path="/home/tzm529/temp/"
del_time=$(date -d "-1 week" +"%Y%m%d")

function backup_today_log()
{
	if [ -e "${nginx_log_path}access.log" ]
	then
		mv ${nginx_log_path}access.log ${backup_log_path}$(date -d "yesterday" +"%Y%m%d")
	fi
}

function move_old_log()
{
	for file in `ls ${backup_log_path}`
	do
		if [ -f "${backup_log_path}${file}" ]; then
			[[ $file<$del_time ]] && unlink ${backup_log_path}${file}
		fi
	done
}

function reopen_nginx_log()
{
	kill -USR1 `cat /soft/nginx/nginx.pid`
}

backup_today_log
move_old_log
reopen_nginx_log
